const SearchTree = require('./SearchTree');
const utils = require('./utils');


function print(root) {
    if (!root) return;
    const queue = [root];
    while (queue.length) {
        const len = queue.length; //记录当前队列的长度
        const row = [];
        for (let i = 0; i < len; i++) {
            const node = queue.shift(); //出队
            row.push(node.val);
            if (node.left) {
                queue.push(node.left)
            };
            if (node.right) {
                queue.push(node.right)
            };
        }
        console.log(`${row} \n`)
    }
}

const root = utils.treeByArr([1,null,2,3]);

function mid(root){
    const stack = [];
    const res = [];
    let cur = root;
    while(stack.length || cur){
        while(cur){
            stack.push(cur);
            cur = cur.left;
        }
        cur = stack.pop();
        res.push(cur.val);
        cur = cur.right;
    }
    return res;
}

// 1
// 23
// 4567
// 89 10 11 12 13 14 15 16
// 425 1 673

var inorderTraversal = function(root) {
    const res = [];
    function dfs(root){
        if(!root) return;
        if(root.left) dfs(root.left);
        res.push(root.val);
        if(root.right) dfs(root.right);
    }
    dfs(root);
    return res;
};
console.log(inorderTraversal(root))